package DTO;

import java.lang.ref.SoftReference;
import java.util.List;


import com.appvn2014.appstorevn.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.ImageSize;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

import android.graphics.Bitmap;
import android.vstore.custom.FadeInRoundedBitmapDisplayer;
import android.widget.ImageView;
import anroid.vstore.provider.Helper;

public class ImageDTO {
	//	public Bitmap image;
	public Bitmap image = null; 
	public String imgURL;
	public void loadImage()
	{
		if(imgURL == null || (image != null))
			return;
		try{
//			imgURL = Helper.SERVICE_URL+imgURL;
			image = ImageLoader.getInstance().loadImageSync(imgURL);
//			Bitmap temp = Helper.getRoundedCornerBitmap(Helper.decodeFile(imgURL),15);

//			image = new SoftReference<Bitmap>(temp);
//			temp.recycle();
		} catch(Exception e){}
	}
	
	public static void displayImage(String url, ImageView imageView)
	{
		imageLoader.displayImage(url, imageView, options);
	}
	public static void displayImage(String url, ImageAware imageAware)
	{
		imageLoader.displayImage(url, imageAware, options);
	}
//	protected static void loadImageByPath(DisplayImageOptions options, String path, ImageViewAware image, ImageLoadingListener listener) {
//        ImageLoader.getInstance().cancelDisplayTask(image);
//        image.getWrappedView().clearAnimation();
//        image.setImageDrawable(null);
//
//        final ImageSize size = ImageSizeUtils.defineTargetSizeForView(image, null);
//        final String cacheKey = MemoryCacheUtil.generateKey(path, size);
//        final List<Bitmap> cachedBitmaps = MemoryCacheUtil.findCachedBitmapsForImageUri(cacheKey, ImageLoader.getInstance().getMemoryCache());
//
//        if (cachedBitmaps.size() > 0) {
//            final Bitmap bitmap = cachedBitmaps.get(0); 
//
//            // Yep, sometimes it is null
//            if (bitmap != null) {
//                if (listener != null) {
//                    listener.onLoadingComplete(path, image.getWrappedView(), bitmap);
//                }
//
//                image.setImageBitmap(bitmap);
//
//                return;
//            }
//        }
//
//        ImageLoader.getInstance().displayImage(path, image, options, listener);
//    }
	
	protected static ImageLoader imageLoader = ImageLoader.getInstance();
	protected static DisplayImageOptions options = new DisplayImageOptions.Builder()
    .showImageOnLoading(null) // resource or drawable
    .showImageForEmptyUri(R.drawable.ic_no_image) // resource or drawable
    .showImageOnFail(R.drawable.ic_no_image) // resource or drawable
    .resetViewBeforeLoading(false)  // default
    .cacheInMemory(true) // default
    .cacheOnDisk(true) // default
    .considerExifParams(false) // default
    .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
    .bitmapConfig(Bitmap.Config.ARGB_8888) // default
    .displayer(new FadeInRoundedBitmapDisplayer(500,15,""))
//    .displayer(new RoundedBitmapDisplayer(15))
    .build();
}
